%%%  $Id$

-define(DVD_BLOCK_LEN, 2048).

%% @type video_manager() = #video_manager{
%% 	last_sector_of_set = integer(),
%% 	last_sector_of_ifo = integer(),
%% 	version = integer(),
%% 	category = integer(),
%% 	number_of_volumes = integer(),
%% 	volume_number = integer(),
%% 	disc_side = integer(),
%% 	number_of_title_sets = integer(),
%% 	provider_identifier = string(),
%% 	pos_code = integer(),
%% 	last_byte = integer(),
%% 	first_play_program_chain = integer(),
%% 	menu_vob = integer(),
%% 	table_of_titles = integer(),
%% 	menu_program_chain_table = integer(),
%% 	parental_management_masks = integer(),
%% 	title_set_attributes = integer(),
%% 	text_data = integer(),
%% 	menu_cell_address_table = integer(),
%% 	menu_vobu_address_map = integer(),
%% 	menu_video_attributes = video_attr(),
%% 	menu_number_of_audio_streams = integer(),
%% 	menu_audio_attributes = [audio_attributes()],
%% 	menu_number_of_subpicture_streams = integer(),
%% 	menu_subpicture_attributes = subpicture_attributes()}.
%%
%% Video Manager Information Management Table
%%
-define(video_manager_size, 512).
-record(video_manager,
		{last_sector_of_set,
		last_sector_of_ifo,
		version,
		category,
		number_of_volumes,
		volume_number,
		disc_side,
		number_of_title_sets,
		provider_identifier,
		pos_code,
		last_byte,
		first_play_program_chain,
		menu_vob,
		table_of_titles,
		menu_program_chain_table,
		parental_management_masks,
		title_set_attributes,
		text_data,
		menu_cell_address_table,
		menu_vobu_address_map,
		menu_video_attributes,
		menu_number_of_audio_streams,
		menu_audio_attributes,
		menu_number_of_subpicture_streams,
		menu_subpicture_attributes}).

%% @type video_title_set() = #video_title_set{
%% 	last_sector_of_set = integer(),
%% 	last_sector_of_ifo = integer(),
%% 	version = integer(),
%% 	category = integer(),
%% 	last_byte = integer(),
%% 	menu_vob = integer(),
%% 	title_vob = integer(),
%% 	table_of_titles_and_chapters = integer(),
%% 	title_program_chain_table = integer(),
%% 	menu_program_chain_table = integer(),
%% 	time_map = integer(),
%% 	menu_cell_address_table = integer(),
%% 	menu_vobu_address_map = integer(),
%% 	title_set_cell_address_table = integer(),
%% 	title_set_vobu_address_map = integer(),
%% 	menu_video_attributes = video_attr(),
%% 	menu_number_of_audio_streams = integer(),
%% 	menu_audio_attributes = [audio_attributes()],
%% 	menu_number_of_subpicture_streams = integer(),
%% 	menu_subpicture_attributes = integer(),
%% 	title_set_video_attributes = video_attr(),
%% 	title_set_number_of_audio_streams = integer(),
%% 	title_set_audio_attributes = [audio_attributes()],
%% 	title_set_number_of_subpicture_streams = integer(),
%% 	title_set_subpicture_attributes = subpicture_attributes(),
%% 	multichannel_extension = [multichannel_extension()]}.
%%
%% Video Title Set Management Table
%%
-define(video_title_set_size, 984). 
-record(video_title_set,
		{last_sector_of_set,
		last_sector_of_ifo,
		version,
		category,
		last_byte,
		menu_vob,
		title_vob,
		table_of_titles_and_chapters,
		title_program_chain_table,
		menu_program_chain_table,
		time_map,
		menu_cell_address_table,
		menu_vobu_address_map,
		title_set_cell_address_table,
		title_set_vobu_address_map,
		menu_video_attributes,
		menu_number_of_audio_streams,
		menu_audio_attributes,
		menu_number_of_subpicture_streams,
		menu_subpicture_attributes,
		title_set_video_attributes,
		title_set_number_of_audio_streams,
		title_set_audio_attributes,
		title_set_number_of_subpicture_streams,
		title_set_subpicture_attributes,
		multichannel_extension}).

%% @type video_attributes() = #video_attributes{
%% 	coding_mode = integer(),
%% 	standard = integer(),
%% 	aspect_ratio = integer(),
%% 	automatic_pan_scan = integer(),
%% 	automatic_letterbox = integer(),
%% 	cc_line21_field1 = integer(),
%% 	cc_line21_field2 = integer(),
%% 	unknown = integer(),
%% 	bit_rate = integer(),
%% 	picture_size = integer(),
%% 	letterboxed = integer(),
%% 	film_mode = integer()}.
%%
%% Video Attributes
%%
-record(video_attributes,
		{coding_mode,         % 0=MPEG-1, 1=MPEG-2
		standard,             % 0=NTSC, 1=PAL
		aspect_ratio,         % 0=4:3, 3=16:9
		automatic_pan_scan,   % 1=disallowed
		automatic_letterbox,  % 1=disallowed
		cc_line21_field1,
		cc_line21_field2,
		unknown,
		bit_rate,
		picture_size,         % 0=720x480(720x576), 1=704x480(704x576)
		                      % 2=352x480(352x576), 3=352x240(352x288)
		letterboxed,          % 0=false, 1=true
		film_mode}).          % 0=camera, 1=film 

%% @type audio_attributes() = #audio_attributes{
%% 	coding_mode = integer(),
%% 	multichannel_extension = integer(),
%% 	language_type = integer(),
%% 	application_mode = integer(),
%% 	quantization_drc = integer(),
%% 	sample_rate = integer(),
%% 	unknown = integer(),
%% 	channels = integer(),
%% 	language_code = [char()],
%% 	language_code_extension = integer(),
%% 	code_extension = integer(),
%% 	karaoke_attributes = karaoke_attributes(),
%% 	surround_attributes = surround_attributes()}.
%%
%% Audio Attributes
%%
-record(audio_attributes,
		{coding_mode,            % 0=AC3, 2=MPEG-1, 3=MPEG-2, 4=LPCM, 6=DTS
		multichannel_extension,
		language_type,           % 0=unspecified, 1=language_code
		application_mode,        % 0=unspecified, 1=karaoke, 2=surround
		quantization_drc,        % coding_mode=MPEG: 0=noDRC, 1=DRC
		                         % coding_mode=LPCM; 0=16bps 1=20bps 2=24bps
		sample_rate,             % 0=48Kbps
		unknown,
		channels,
		language_code,           % ISO 639 language code (e.g. "en" = english)
		language_code_extension,
		code_extension,          % 0=unspecified, 1=normal, 2=visually impaired
		                         % 3=directors comments, 4=alternate comments
		karaoke_attributes,
		surround_attributes}).

%% @type karaoke_attributes() = #karaoke_attributes{
%% 	unknown = integer(),
%% 	channel_assignments = integer(),
%% 	version = integer(),
%% 	mc_intro = integer(),
%% 	mode = integer()}.
%%
%% Karaoke attributes
%%
-record(karaoke_attributes,
		{unknown,
		channel_assignments,
		version,
		mc_intro,
		mode}).                  % 0=solo, 1=duet

%% @type surround_attributes() = #surround_attributes{
%% 	unknown1 = integer(),
%% 	dolby_encoded = integer(),
%% 	unknown2 = integer()}.
%%
%% Surround attributes
%%
-record(surround_attributes,
		{unknown1,
		dolby_encoded,
		unknown2}).

%% @type subpicture_attributes() = #subpicture_attributes{
%% 	coding_mode = integer(),
%% 	language_type = integer(),
%% 	language_code = integer(),
%% 	language_code_extension = integer(),
%% 	code_extension = integer()}.
%%
%% Subpicture Attributes
%%
-record(subpicture_attributes,
		{coding_mode,             % 0 = 2 bit rle
		language_type,            % 0=unspecified, 1=language_code
		language_code,
		language_code_extension,
		code_extension}).

%% @type user_operations() = #user_operations{
%% 	video_pres_mode_change = integer(),
%% 	karaoke_audio_pres_mode_change = integer(),
%% 	angle_change = integer(),
%% 	subpic_stream_change = integer(),
%% 	audio_stream_change = integer(),
%% 	pause_on = integer(),
%% 	still_off = integer(),
%% 	button_select_or_activate = integer(),
%% 	resume = integer(),
%% 	chapter_menu_call = integer(),
%% 	angle_menu_call = integer(),
%% 	audio_menu_call = integer(),
%% 	subpic_menu_call = integer(),
%% 	root_menu_call = integer(),
%% 	title_menu_call = integer(),
%% 	backward_scan = integer(),
%% 	forward_scan = integer(),
%% 	next_pg_search = integer(),
%% 	prev_or_top_pg_search = integer(),
%% 	time_or_chapter_search = integer(),
%% 	go_up = integer(),
%% 	stop = integer(),
%% 	title_play = integer(),
%% 	chapter_search_or_play = integer(),
%% 	title_or_time_play = integer()}.
%%
%% User Operations
%%
-define(user_operations_size, 4).
-record(user_operations,
		{video_pres_mode_change,
		karaoke_audio_pres_mode_change,
		angle_change,
		subpic_stream_change,
		audio_stream_change,
		pause_on,
		still_off,
		button_select_or_activate,
		resume,
		chapter_menu_call,
		angle_menu_call,
		audio_menu_call,
		subpic_menu_call,
		root_menu_call,
		title_menu_call,
		backward_scan,
		forward_scan,
		next_pg_search,
		prev_or_top_pg_search,
		time_or_chapter_search,
		go_up,
		stop,
		title_play,
		chapter_search_or_play,
		title_or_time_play}).

%% @type program_chain() = #program_chain{
%% 	number_of_programs = integer(),
%% 	number_of_cells = integer(),
%% 	playback_time = integer(),
%% 	prohibited_user_operations = integer(),
%% 	audio_stream_control = list(),
%% 	subpicture_stream_control = list(),
%% 	next_program_chain = integer(),
%% 	previous_program_chain = integer(),
%% 	go_up_program_chain = integer(),
%% 	still_time = integer(),
%% 	playback_mode = integer(),
%% 	palette = list(),
%% 	commands = integer(),
%% 	program_map = integer(),
%% 	cell_playback = integer(),
%% 	cell_position = integer()}.
%%
%% Program Chain Information
%%
-define(program_chain_size, 236).
-record(program_chain,
		{number_of_programs,
		number_of_cells,
		playback_time,
		prohibited_user_operations,
		audio_stream_control,
		subpicture_stream_control,
		next_program_chain,
		previous_program_chain,
		go_up_program_chain,
		still_time,
		playback_mode,
		palette,
		commands,
		program_map,
		cell_playback,
		cell_position}).

%% @type title() = #title{
%% 	title_type = integer(),
%% 	number_of_angles = integer(),
%% 	number_of_chapters = integer(),
%% 	parental_management_mask = integer(),
%% 	title_set_number = integer(),
%% 	title_number = integer(),
%% 	start_sector = integer()}.
%%
%% Table of Titles
%%
-record(title,
		{title_type,
		number_of_angles,
		number_of_chapters,
		parental_management_mask,
		title_set_number,
		title_number,
		start_sector}).

%% @type language_unit() = #language_unit{
%% 	language_code = integer(),
%% 	language_code_extension = integer(),
%% 	exists = integer(),
%% 	menu_program_chains = [menu_program_chain()]}.
%%
%% Language Unit
%%
-record(language_unit,
		{language_code,
		language_code_extension,
		exists,
		menu_program_chains}).

%% @type menu_program_chain() = #menu_program_chain{
%% 	category = integer(),
%% 	parental_mangement_mask = integer(),
%% 	program_chain = program_chain()}.
%%
%% Menu Program Chain
%%
-record(menu_program_chain,
		{category,
		parental_management_mask,
		program_chain}).

%% @type dvd_time() = #dvd_time{
%% 	hour = integer(),
%% 	minute = integer(),
%% 	second = integer(),
%% 	frame_u= integer()}.
%%
%% DVD Time Information
%%
-record(dvd_time,
		{hour,
		minute,
		second,
		frame_u}).

%% @type command_table() = #command_table{
%% 	pre_commands = list(),
%% 	post_commands = list(),
%% 	cell_commands = list()}.
%%
%% PGC Command Table
%%
-record(command_table,
		{pre_commands,
		post_commands,
		cell_commands}).

%% @type cell_playback() = #cell_playback{
%% 	cell_type = integer(),
%% 	block_type = integer(),
%% 	seamless_playback_linked_in_pci = integer(),
%% 	interleaved = integer(),
%% 	stc_discontinuity = integer(),
%% 	seamless_angle_linked_in_dsi = integer(),
%% 	restricted = integer(),
%% 	still_time = integer(),
%% 	command_number = integer(),
%% 	playback_time = integer(),
%% 	first_vobu_start_sector = integer(),
%% 	first_ilvu_end_sector = integer(),
%% 	last_vobu_start_sector = integer(),
%% 	last_vobu_end_sector = integer()}.
%%
%% Cell Playback
%% 
-record(cell_playback,
		{cell_type,
		block_type,
		seamless_playback_linked_in_pci,
		interleaved,
		stc_discontinuity,
		seamless_angle_linked_in_dsi,
		restricted,
		still_time,
		command_number,
		playback_time,
		first_vobu_start_sector,
		first_ilvu_end_sector,
		last_vobu_start_sector,
		last_vobu_end_sector}).

%% @type multichannel_extension() = #multichannel_extension{
%% 	ach0_guide_melody = integer(),
%% 	ach1_guide_melody = integer(),
%% 	ach2_guide_vocal_1 = integer(),
%% 	ach2_guide_vocal_2 = integer(),
%% 	ach2_guide_melody_1 = integer(),
%% 	ach2_guide_melody_2 = integer(),
%% 	ach3_guide_vocal_1 = integer(),
%% 	ach3_guide_vocal_2 = integer(),
%% 	ach3_guide_melody_A = integer(),
%% 	ach3_sound_effect_A = integer(),
%% 	ach4_guide_vocal_1 = integer(),
%% 	ach4_guide_vocal_2 = integer(),
%% 	ach4_guide_melody_B = integer(),
%% 	ach4_sound_effect_B = integer()}.
%%
%% MultiChannel Extension (Karaoke mode)
%% 
-record(multichannel_extension,
		{
		ach0_guide_melody,
		ach1_guide_melody,
		ach2_guide_vocal_1,
		ach2_guide_vocal_2,
		ach2_guide_melody_1,
		ach2_guide_melody_2,
		ach3_guide_vocal_1,
		ach3_guide_vocal_2,
		ach3_guide_melody_A,
		ach3_sound_effect_A,
		ach4_guide_vocal_1,
		ach4_guide_vocal_2,
		ach4_guide_melody_B,
		ach4_sound_effect_B}).

